<?php
	require_once (__DIR__.'../models/App.php');
	require_once (__DIR__.'/LogDao.php');
	
	define("APP_TBL", "rate_app");
	define("DEV_TBL", "rate_developer");
	
	function selectApp($appId){
		
		$statement = "SELECT app.name as name, "
			. "app.description as description, "
			. "app.android_link as android_link, "
			. "app.apple_link as apple_link, "
			. "app.win_link as win_link, "
			. "app.webseite as webseite "
		. "FROM " . APP_TBL . " app "
		. "WHERE id = ". $appId;
		
		$query = mysql_query($statement);
		
		if(!$query){
			writeError("selectApp: Cannot query the database: " . mysql_error());
		}
		
		$row = mysql_fetch_array($query);
		
		$app = new App();
		$app->name = $row["name"];
		$app->description = $row["description"];
		$app->android_link = $row["android_link"];
		$app->apple_link = $row["apple_link"];
		$app->win_link = $row["win_link"];
		$app->webseite = $row["webseite"];
				
		return $app;
	}
	
	function selectMaxAppId(){
		
		$statement = "SELECT MAX(id) as max_id FROM " . APP_TBL;
		
		$query = mysql_query($statement);

		if(!$query){
			writeError("selectMaxAppId: Cannot query the database: " . mysql_error());
		}
		
		$row = mysql_fetch_array($query);
		
		return $row["max_id"];
	}

?>